//
//  QNSemiModalView.h
//
//  Created by rsh on 2019/11/16.
//  Copyright © 2019年 rsh. All rights reserved.
//

#import <UIKit/UIKit.h>

// MARK: 类似于京东商品详情点击后的半推框视图

typedef void (^SemiModalViewWillCloseBlock)(void);
typedef void (^SemiModalViewDidCloseBlock)(void);

@interface QNSemiModalView : UIView

@property (nonatomic, copy) SemiModalViewWillCloseBlock semiModalViewWillCloseBlock;
@property (nonatomic, copy) SemiModalViewDidCloseBlock semiModalViewDidCloseBlock;

@property (strong, nonatomic) UIView *contentView;
@property (nonatomic, assign) BOOL narrowedOff;
@property (nonatomic, assign) NSTimeInterval animationTime;

- (id)initWithSize:(CGSize)size andBaseViewController:(UIViewController *)baseViewController;
- (void)close;
- (void)open;



/**
 *用法解析:
 1.在要弹出缩小动画的控制器中，引入该QNSemiModalView，和相应要弹出的view
 如下：
 @property (strong, nonatomic) QNSemiModalView *modalView;           // 优惠券
 @property (strong, nonatomic) GPCouponsListView *couponsView;
 @property (strong, nonatomic) QNSemiModalView *specModalView;       // 规格
 @property (strong, nonatomic) GPSpecsListView *specsView;
 @property (strong, nonatomic) QNSemiModalView *tradeModalView;      // 促销
 @property (strong, nonatomic) GPTradeListView *tradeView;
 @property (strong, nonatomic) QNSemiModalView *addresModalView;     // 地址
 @property (strong, nonatomic) GPAddressListView *addresView;
 
 
 
 2.在dealloc中移除
 - (void)dealloc {
 // MARK: 临时方案，解决半推框内存泄漏问题
 [_modalView removeFromSuperview];
 _modalView = nil;
 
 [_specModalView removeFromSuperview];
 _specModalView = nil;
 
 [_tradeModalView removeFromSuperview];
 _tradeModalView = nil;
 
 [_tradeView removeFromSuperview];
 _tradeView = nil;
}
 
 3.懒加载QNSemiModalView和相应的弹出view
 
 - (QNSemiModalView *)modalView {
 if (_modalView == nil) {
 _modalView = [[QNSemiModalView alloc] initWithSize:CGSizeMake(ASScreenWidth, ASScreenHeight * 0.7) andBaseViewController:self.navigationController];
 _modalView.contentView.backgroundColor = ASColorHex(0xF9F9F9);
 //        _modalView.narrowedOff = YES; // 普通半推框展示
 
 ASWeak(self);
 _modalView.semiModalViewDidCloseBlock = ^{
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 }
 return _modalView;
 }
 
 - (GPCouponsListView *)couponsView {
 if (_couponsView == nil) {
 _couponsView = GPCouponsListView.alloc.init;
 }
 return _couponsView;
 }
 
 - (QNSemiModalView *)specModalView {
 if (_specModalView == nil) {
 _specModalView = [[QNSemiModalView alloc] initWithSize:CGSizeMake(ASScreenWidth, ASScreenHeight * 0.8) andBaseViewController:self.navigationController];
 _specModalView.contentView.backgroundColor = UIColor.whiteColor;
 //        _specModalView.narrowedOff = YES; // 普通半推框展示
 
 ASWeak(self);
 _specModalView.semiModalViewDidCloseBlock = ^{
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 }
 return _specModalView;
 }
 
 - (GPSpecsListView *)specsView {
 if (_specsView == nil) {
 _specsView = GPSpecsListView.alloc.init;
 _specsView.invitationCode = self.invitationCode;
 }
 return _specsView;
 }
 
 
 - (QNSemiModalView *)tradeModalView {
 if (_tradeModalView == nil) {
 _tradeModalView = [[QNSemiModalView alloc] initWithSize:CGSizeMake(ASScreenWidth, ASScreenHeight * 0.6) andBaseViewController:self.navigationController];
 _tradeModalView.contentView.backgroundColor = UIColor.whiteColor;
 
 ASWeak(self);
 _tradeModalView.semiModalViewDidCloseBlock = ^{
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 }
 return _tradeModalView;
 }
 
 - (GPTradeListView *)tradeView {
 if (_tradeView == nil) {
 _tradeView = GPTradeListView.alloc.init;
 }
 return _tradeView;
 }
 
 - (QNSemiModalView *)addresModalView {
 if (_addresModalView == nil) {
 _addresModalView = [[QNSemiModalView alloc] initWithSize:CGSizeMake(ASScreenWidth, ASScreenHeight * 0.7) andBaseViewController:self.navigationController];
 _addresModalView.contentView.backgroundColor = UIColor.whiteColor;
 
 ASWeak(self);
 _addresModalView.semiModalViewDidCloseBlock = ^{
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 }
 return _addresModalView;
 }
 
 - (GPAddressListView *)addresView {
 if (_addresView == nil) {
 _addresView = GPAddressListView.alloc.init;
 }
 return _addresView;
 }
 
 
 
 4.viewDidLoad中添加相应的view和QNSemiModalView，并执行相应的选择器事件回调
 
 
 // MARK: -----------选择器初始化-------------
 // MARK: 优惠券弹框视图
 [self.modalView.contentView addSubview:self.couponsView];
 [self.couponsView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.edges.mas_equalTo(0);
 }];
 
 // MARK: 规格弹框视图
 [self.specModalView.contentView addSubview:self.specsView];
 [self.specsView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.edges.mas_equalTo(0);
 }];
 
 // MARK: 活动标签弹框视图
 [self.tradeModalView.contentView addSubview:self.tradeView];
 [self.tradeView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.edges.mas_equalTo(0);
 }];
 
 // MARK: 地址选择弹框视图
 [self.addresModalView.contentView addSubview:self.addresView];
 [self.addresView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.edges.mas_equalTo(0);
 }];
 
 // MARK: -----------选择器事件回调-------------
 ASWeak(self);
 self.couponsView.exitCallBack = ^{
 [weakself.modalView close];
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 
 self.couponsView.selectedCallBack = ^(NSString * _Nonnull couponId) {
 [weakself getCanReceiveCouponsCouponId:couponId];
 };
 
 self.specsView.exitCallBack = ^{
 [weakself.specModalView close];
 [weakself queryCartCount:nil];
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 
 self.specsView.selectedCallBack = ^(NSArray *goods) {
 [weakself.specModalView close];
 weakself.player.view.hidden = NO;
 [weakself.player play];
 
 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(weakself.specModalView.animationTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
 GPCreateOrderVC *vc = [[UIStoryboard storyboardWithName:GPOrderStoryboard bundle:nil] instantiateViewControllerWithIdentifier:@"GPCreateOrderVC"];
 vc.addressList = weakself.addressModelArrM;
 vc.buySelectedsArray = goods.mutableCopy;
 //            vc.goodsCountLimit = weakself.limitCount;
 if (weakself.currentAddress) {
 vc.selectAddress = weakself.currentAddress;
 } else {
 vc.selectAddress = nil;
 }
 [weakself.navigationController pushViewController:vc animated:YES];
 });
 };
 
 self.tradeView.exitCallBack = ^{
 [weakself.tradeModalView close];
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 
 self.addresView.exitCallBack = ^{
 [weakself.addresModalView close];
 weakself.player.view.hidden = NO;
 [weakself.player play];
 };
 
 self.addresView.creatAddressBlock = ^{
 [weakself.addresModalView close];
 weakself.player.view.hidden = NO;
 [weakself.player play];
 
 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(weakself.specModalView.animationTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
 //            GPCreateAddressVC *vc = [[UIStoryboard storyboardWithName:GPAddressStoryboard bundle:nil] instantiateViewControllerWithIdentifier:@"GPCreateAddressVC"];
 //            vc.creatAddressBlock = ^{
 //                [weakself requeryAddressData];
 //            };
 
 UIViewController *vc = [GPMediator.sharedInstance fetchGPCreateAddressVC:^{
 [weakself requeryAddressData];
 }];
 [weakself.navigationController pushViewController:vc animated:YES];
 });
 };
 
 self.addresView.selectAddressBlock = ^(GPAddress *address) {
 [weakself.addresModalView close];     //执行相应close方法
 weakself.player.view.hidden = NO;
 [weakself.player play];
 weakself.currentAddress = address;
 [weakself queryTransportFee];
 [weakself queryStockProductDisplay:GPSpecSelectorSourcePPOther];
 };
 
 
 5.在相应的点击触发该动画效果的按钮响应方法中执行：
 
 [self.modalView open]; // 相关回调 initSubviews 中初始化

 [self.tradeModalView open]; // 相关回调 initSubviews 中初始化
 
 [self.addresModalView open];  // 相关回调 initSubviews 中初始化
 
 
 
 注意：首页懒加载添加相应的view，然后open，然后close
 
 
 
 **/





@end
